<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/public/header.jsp"%>
<html>
	<head>
		<title>客户管理</title>
	<script type="text/javascript">
		$(function(){
			$("#customerManage").layout();
			
			$("#searchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
		   	}); 
			
			$("#type_id").combotree({
				url:'<%=contextPath %>/springMVC/group/getSystemTypeTree?type=1',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch();
				}
			});
			
			$('#table').datagrid({
				title:'客户资料管理',
				rownumbers:true,
				url:'<%=contextPath %>/springMVC/crm/listPageCustomer',
				loadMsg:'正在加载数据，请稍后......',
				fitColumns:true,
				nowrap:false,
				idField:'id',
				frozenColumns:[[
	                {field:'ck',checkbox:true},
				    {title:'主键',field:'id',hidden:true}
				]],
				columns:[[
					{title:'客户类别',field:'type_name',width:200,align:'center'},
					{title:'公司名称',field:'company',width:200,align:'center'},
					{title:'联系人',field:'contact',width:200,align:'center'},
					{title:'TEL',field:'tel',width:200,align:'center'},
					{title:'应收账款',field:'finance_in',width:100,align:'center'},
					{title:'编辑',field:'edit',width:200,align:'center',formatter:function(value,rowData,rowIndex){
						var supplierId = rowData.id;
						return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-edit' title='编辑' onclick=\"javascript:addOrEditCustomer(1,'"+ supplierId +"');\">";
					}},
					{title:'往来流水',field:'detial',width:200,align:'center',formatter:function(value,rowData,rowIndex){
						return "<input type='button'   style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details'   onclick=\"javascript:detailCustomer('"+ rowData.id +"');\">";
					}}
				]],
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				toolbar:'#tb'
			});
		});
		
		function detailCustomer(customer_id){
			openDialogResize("<%=contextPath %>/springViews/crm/customerFinanceInDetail.jsp?customer_id="+customer_id,1000, 800);
		}
		
		function rtCallBack(){
			$('#table').datagrid('reload');
		}
		function deleteRows(){
			var rows=$('#table').datagrid('getSelections');
			var deleteVar="";
			if(rows.length==0)
			{
				$.messager.alert('提示','选中要删除的记录');  
				return ;
			}
			for(var i=0;i<rows.length;i++)
			{
				if(i==(rows.length-1))
				{
					deleteVar+=rows[i].id;
				}else
				{
					deleteVar+=rows[i].id+",";
				}
			}
			$.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/crm/deleteCustomer",
						data:"ids="+deleteVar,
						dataType:"json",
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								$.messager.alert('提示：',rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
		function addOrEditCustomer(type,id){
			if(type==0){
				openDialogResize("<%=contextPath %>/springViews/crm/addOrEditCustomer.jsp?callback=rtCallBack",1000, 800);
			}else{
				openDialogResize('<%=contextPath %>/springViews/crm/addOrEditCustomer.jsp?callback=rtCallBack&id='+id,1000, 800);
			}
		}
		function doSearch()
		{
			var searchValue = $('#searchValue').val();
			var type_id = $('#type_id').combotree('getValue');
			$('#table').datagrid('load',{
				searchValue:searchValue,
				type_id:type_id
				});
		}
	</script>
	</head>
	<body style="height: 97%">
		<div id="customerManage" class="easyui-layout" data-options="fit:true">
			<div region="center"  style="padding:5px;">
			    	<div id="table" data-options="fit:true"></div>
			    	<div id="tb" style="padding:3px;height:auto">
						<div style="float:left;">
							<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="deleteRows();">删除</a>
							<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addOrEditCustomer(0);">新增</a>
						</div>
						<div align="right">
							分类：<input  id="type_id" name="type_id" class="easyui-combotree">
							查询条件：<input id="searchValue" name="searchValue" style="width:150px" title="客户名称或联系人"/>&nbsp;&nbsp;
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
						</div>
					</div>
		    </div>
		</div>
	</body>
</html>